/**     
 * @Title: Producer.java   
 * @Package me.mq.producer   
 * @Description: TODO
 * @author weiwei 
 * @date 2018年5月30日 上午9:41:51   
 * @version V1.0     
 */
package me.mq.producer;

import me.mq.config.RabbitMQConfiguration;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.lang.Console;

/**
 * @ClassName: Producer
 * @Description: TODO
 * @author weiwei
 * @date 2018年5月30日 上午9:41:51
 * 
 */
@RestController
public class Producer {

	@Autowired
	private RabbitTemplate rabbitTemplate;

	@GetMapping("/sendMessage")
	public Object sendMessage() {
		new Thread(() -> {
			for (int i = 0; i < 100; i++) {
				String value = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
				Console.log("send message {}", value);
				rabbitTemplate.convertAndSend(RabbitMQConfiguration.EXCHANGE_NAME, RabbitMQConfiguration.ROUTING_KEY, value);
			}
		}).start();
		return "ok";
	}
}
